<template>
  <div>
    <navgitar title="栏目管理"></navgitar>
    <div class="main">
      <h2>点击删除以下频道</h2>
      <div class="top_list">
        <div class="item" v-for="(value,index) in arrTop" :key='index' @click="cutlist(value,index)">{{value.name}}</div>  
      </div>
      <h2>点击添加以下频道</h2>
      <div class="top_list" >
        <div class="item" v-for='(value,index) in arrDown' :key='index' @click="addlist(value,index)">{{value.name}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import navgitar from "../components/navgitar";
export default {
  data(){
    return{
         categorylist:[],
         arrTop:[],
         arrDown:[]
    }
  },
  watch:{
      categorylist(){
          localStorage.setItem('categorylist',JSON.stringify(this.categorylist))
      }
  },
  components: {
    navgitar,
  },
  methods:{
     cutlist(value,index){
      //  console.log('232');
       this.arrTop.splice(index,1)
      value.is_top=0
      this.arrDown.push(value)     
     },
     addlist(value,index){
       this.arrDown.splice(index,1)
       value.is_top=1
       this.arrTop.push(value)
     }
  },
  created(){
    this.$axios({
      url:"/category",
    }).then((res)=>{
      // console.log(res);
      this.categorylist=res.data.data
      console.log(this.categorylist);
      this.categorylist=this.categorylist.filter(v=>{
        return v.name !=''
      })
      this.arrTop=this.categorylist.filter((v)=>{
        return v.is_top ==1
      })
      this.arrDown = this.categorylist.filter((v)=>{
        return v.is_top==0
      })
      console.log('this.categorylist',this.categorylist);
      console.log(132,this.arrTop);
      console.log(23223,this.arrDown);
    })
  },
};
</script>
<style lang="less" scoped>
.main{
  padding: 20/360*100vw;
  h2{
    font-size: 16px;
    font-weight: normal;
    color: #888;    
  }
   .top_list{
     margin-top: 20/360*100vw;
        display: flex;
        // justify-content: space-around;
        // align-items: center;
        flex-wrap: wrap;
        .item{
          padding: 5/360*100vw 8/360*100vw;
          line-height: 30/360*100vw;
          border: 1px solid #999;
          margin-bottom: 7/360*100vw; 
          margin-right: 15/360*100vw;                 
        }
    }

}
</style>